package com.coocaa.ops.admin.v1.module.biz.impl;

import com.coocaa.ops.admin.base.AbstractBizImpl;
import com.coocaa.ops.admin.v1.dmp.biz.impl.DmpRegistryRlsInfoBizImpl;
import com.coocaa.ops.admin.v1.homepage.mapper.IHomepageModuleRlsMapper;
import com.coocaa.ops.admin.v1.module.biz.IModuleInfoBiz;
import com.coocaa.ops.admin.v1.module.mapper.IModuleInfoHistoryMapper;
import com.coocaa.ops.admin.v1.module.mapper.IModuleInfoMapper;
import com.coocaa.ops.admin.v1.module.mapper.IModuleRlsTabQueryMapper;
import com.coocaa.ops.admin.v1.module.model.query.ModuleRlsTabQueryModel;
import com.coocaa.ops.common.core.base.enums.ResourceTypeEnum;
import com.coocaa.ops.common.core.base.mapper.IBaseHistoryMapper;
import com.coocaa.ops.common.core.base.mybatis.QueryTemplate;
import com.coocaa.ops.common.core.biz.homepage.entity.HomepageModuleRlsEntity;
import com.coocaa.ops.common.core.biz.module.entity.ModuleInfoEntity;
import com.coocaa.ops.common.core.biz.module.entity.ModuleInfoHistoryEntity;
import com.coocaa.ops.common.core.biz.module.entity.ModuleTabContentConfigInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author bjh
 * @description 模块信息原始表-biz层接口实现
 * @date 2020-06-15 16:34:46
 */
@Service
public class  ModuleInfoBizImpl extends AbstractBizImpl<IModuleInfoMapper, ModuleInfoEntity> implements  IModuleInfoBiz {
    @Autowired
    private IModuleInfoHistoryMapper thisHistoryMapper;
    @Autowired
    private IModuleRlsTabQueryMapper moduleRlsTabQueryMapper;
    @Autowired
    private IHomepageModuleRlsMapper homepageModuleRlsMapper;
    @Autowired
    private DmpRegistryRlsInfoBizImpl dmpRegistryRlsInfoBiz;


    @Override
    public IBaseHistoryMapper getHistoryMapper() {
        return thisHistoryMapper;
    }

    @Override
    public ModuleInfoEntity createOriginEntityNewInstance() {
        return new ModuleInfoEntity();
    }

    @Override
    public ModuleInfoHistoryEntity createHistoryEntityNewInstance() {
    ModuleInfoHistoryEntity historyEntity = new ModuleInfoHistoryEntity();
        return historyEntity;
    }

    @Override
    public List<ModuleTabContentConfigInfo> queryDmpTabList(ModuleRlsTabQueryModel model) {
        return moduleRlsTabQueryMapper.queryDmpTabList(model);
    }

    @Override
    public boolean isModuleHasUsed(Integer moduleId) {
        QueryTemplate<HomepageModuleRlsEntity> queryTemplate = QueryTemplate.getEqQueryTemplate("flag", 1);
        queryTemplate.lambda().eq(HomepageModuleRlsEntity::getModuleId, moduleId);
        return homepageModuleRlsMapper.selectCount(queryTemplate) > 0 || dmpRegistryRlsInfoBiz.isResourceHasUsed(moduleId, ResourceTypeEnum.MODULE.getValue());

    }
}
